#include"DEMOGameState_Context.h"


DEMOGameState_Context::DEMOGameState_Context()
{
	//m_stateflag = EDGS_TEST1;
	m_stateflag = EDGS_Gameplay;
	m_GameState = NULL;
	GotoGameState(m_stateflag);
}

DEMOGameState_Context::DEMOGameState_Context(EDemoGameState targetState)
{
	m_stateflag = targetState;
	m_GameState = NULL;
	GotoGameState(m_stateflag);	
}


void DEMOGameState_Context::GotoGameState(EDemoGameState targetState)
{
	if( m_GameState != NULL)
	{
		m_GameState->OnDestroy();
		delete m_GameState;
		m_GameState = NULL;
	}

	switch(targetState)
	{
	case EDGS_TEST1:
		m_GameState = new DEMOGameState_Test1();
		break;
	case EDGS_TEST2:
		m_GameState = new DEMOGameState_Test2();
		break;
	case EDGS_Gameplay:
		m_GameState = new DEMOGameState_Gameplay();
		break;
	default:
		m_GameState = NULL;
		/*MessageBox(NULL,TEXT("Error Game State Type."),TEXT("Error"),MB_OK);*/
		printf("Error Game State Type!\n");
		break;
	}

	if( m_GameState != NULL )
	{
		m_GameState->OnInit(this);
	}
}

DEMOGameState_Context::~DEMOGameState_Context()
{
	if( m_GameState != NULL)
	{
		delete m_GameState;
		m_GameState = NULL;
	}
	m_stateflag = EDGS_MAX;
}

bool DEMOGameState_Context::Tick(float dt)
{
	if( m_GameState != NULL )
	{
		return m_GameState->Tick(dt);
	}

	return false;
}

bool DEMOGameState_Context::Render()
{
	if( m_GameState != NULL )
	{
		return m_GameState->Render();
	}
	return false;
}

DEMOGameState_Base* DEMOGameState_Context::GetGameState()
{
	return m_GameState;
}